package com.online.onlinestudent.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.online.onlinestudent.entity.Course;
import com.online.onlinestudent.entity.Record;
import com.online.onlinestudent.entity.Student;
import com.online.onlinestudent.entity.Teacher;
import com.online.onlinestudent.mapper.StudentMapper;
import com.online.onlinestudent.service.StudentService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Override
    public List<Student> fuzzyQueryByUsername(String username) {
        QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("username", username);
        List<Student> list=baseMapper.selectList(queryWrapper);
        if (list.isEmpty()||list==null){
            return new ArrayList<>();
        }
        return list;
    }

    @Override
    public List<Student> getAllStudentByRecord(List<Record> records) {
        List<Student> students = new ArrayList<>();
        for (Record record : records) {
            QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("id", record.getStudentId());
            List<Student> list=baseMapper.selectList(queryWrapper);
            students.addAll(list);
        }

        return students;
    }
}
